﻿// Study0807.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第八章 多态 实验
//声明Point类，有坐标_x,_y两个成员变量，对Point类重载“++”,"--"运算符，实现对坐标值的改变


#include <iostream>
using namespace std;

class Point
{
public:
	Point(int xx = 0, int yy = 0) :_x(xx), _y(yy) {}
	int getX() const {
		return _x;
	}
	int getY() const {
		return _y;
	}
	Point& operator ++()
	{
		this->_x++;
		this->_y++;
		return *this;
	}
	Point operator ++(int)
	{
		const Point old = *this;
		++(*this);
		return old;
	}
	Point& operator --()
	{
		this->_x--;
		this->_y--;
		return *this;
	}
	Point operator --(int)
	{
		const Point old = *this;
		--(*this);
		return old;
	}
	friend ostream& operator<<(ostream& out,const Point& p);
private:
	int _x, _y;
};

ostream& operator<<(ostream& out,const Point& p)
{
	out << "(" << p._x<< "," << p._y << ")";
	return  out;
}

int main()
{
	Point p1(5, 10);
	cout << "p1:"<<p1<<endl;
	cout << "p1++:"<<p1++<<endl;
	cout << "p1--:"<<p1--<<endl;
	
	return 0;
}

